<template>
  <div>
    <ComTable
      @handleCurrentChange="handleCurrentChange"
      @handleSizeChange="handleSizeChange"
      :config="config"
      :pagination="{
        total: pageing.total,
        pageNum: pageing.pageNum,
        pageSize: pageing.pageSize,
      }"
      :list="getBrowselisttable"
      :modes="consumptionModes"
    >
    </ComTable>
  </div>
</template>

<script>
import ComTable from "@/wss/components/comTable.vue";
import {getBrowselist,selectCircleMasterlist} from "@/wss/newApi_3-24/askAround/index";
export default {
  name: "Browse",
  components: { ComTable },
  data() {
    return {
      // 表格配置
      config: {
        // border: true,
        isAdd: false,
        loading: false,
      },
      // 圈员ID
      masetrid:"",
      // 浏览纪录数据
      getBrowselisttable:[],
      //圈员成员
      Browseoptions:[],
      // 父主键传过来搜索参数
      seachdata:{},
      //圈主消费详情表格
      consumptionModes: [
        {
          label: "浏览内容",
          mode: "title",
          showOverflowTooltip: true,
        },
        {
          label: "圈员",
          mode: "nickname",
          showOverflowTooltip: true,
        },
        {
          label: "进入时间",
          mode: "startTime",
          showOverflowTooltip: true,
        },
        {
          label: "停留时长（秒）",
          mode: "stayTime",
          showOverflowTooltip: true,
        },
      ],
      // 分页参数
      pageing: { pageNum: 1, pageSize: 10, total: 0 },
    };
  },

  mounted(){
    // 
      this.$bus.$off("SeachBrowseFrom")
      this.$bus.$on("SeachBrowseFrom", (item) => {
      this.seachdata=item
      this.getBrowselistfn();
    
    });
  },
  methods: {
   //查询列表
   async  Browselist(val){
     this.masetrid=val
     await  this.getBrowselistfn();
     await  this.Browseoptionsuser();
    },
     //查询浏览记录
    async getBrowselistfn() {
      // 清空上次搜索的列表
      this.Browseoptions = [];
      let newdata = {
        nickname: this.seachdata,
        circleId: this.masetrid,
        pageNum: this.pageing.pageNum,
        pageSize: this.pageing.pageSize,
      };
      let { code, rows,total } = await getBrowselist(newdata);
      if (code == 200) {
        this.pageing.total=total
        // 转时间格式 220901
        let arr = rows;
        // console.log(this.Browseoptions, " this.Browseoptions");
        this.getBrowselisttable = arr;
      }
    },
      //查询圈员的成员
    async Browseoptionsuser() {
      //再次请求的时候清空上一次的列表数据
      this.Browseoptions = [];
      let { code, rows } = await selectCircleMasterlist({
        circleId: this.masetrid,
      });
      if (code == 200) {
        let obj = rows;
        for (const key in obj) {
          this.Browseoptions.push({
            value: obj[key].nickname,
            label: obj[key].nickname,
          });
        }
        let map = new Map();
        for (let item of this.Browseoptions) {
          if (!map.has(item.value)) {
            map.set(item.value, item);
          }
        }
        this.Browseoptions = [...map.values()];
        this.$emit("Browseoptionslist", this.Browseoptions)
      }
    },
    // 转时间格式 220901
    getTime(days) {
      let time = days.split(" ")[0];
      let arr = time.split("-");
      return arr[0].slice(2) + arr[1] + arr[2];
    },
   
      handleCurrentChange(pageNum) {
      this.pageing.pageNum = pageNum;
      this.getBrowselistfn(this.seachdata);
    },
    // 页容量发生改变
    handleSizeChange(pageSize) {
      this.pageing.pageSize = pageSize;
      this.getBrowselistfn(this.seachdata);
    },
  },
};
</script>

<style>
</style>